<?php

namespace App\Admin\Controllers;

use App\Models\Order;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class OrderController extends AdminController
{


    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '订单管理';


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $status = config('order.status'); //状态
        $product_version = config('order.product_version'); //商品版本
        $ways_purchase = config('order.ways_purchase'); //购买方式
        $grid = new Grid(new Order());

        $grid->column('id', __('id'));
        $grid->column('order_id', __('订单号'));
        $grid->column('product_version', __('商品版本'))->using($product_version)->filter($product_version);
        $grid->column('ways_purchase', __('购买方式'))->using($ways_purchase)->filter($ways_purchase);
        $grid->column('server', __('所在区服'));
        $grid->column('game_id', __('游戏id'));
        $grid->column('contact_details', __('联系方式'));
        $grid->column('status', __('状态'))->using($status)->filter($status)->label();
        $grid->column('remark', __('备注'));
        $grid->column('created_at', __('创建时间'))->sortable();
        $grid->column('updated_at', __('更新时间'))->sortable();
        $grid->disableCreateButton(); //禁用创建
        $grid->disableRowSelector(); //禁用行选择checkbox
        $grid->filter(function ($filter) {
            $filter->disableIdFilter(); //禁用id搜索
            $filter->between('created_at', '创建时间')->datetime();
            $filter->like('order_id', '订单号');
        });
        $grid->actions(function ($actions) {
            $actions->disableDelete(); // 去掉删除
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Order::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('order_id', __('订单号'));
        $show->field('product_version', __('商品版本'));
        $show->field('ways_purchase', __('购买方式'));
        $show->field('server', __('所在区服'));
        $show->field('game_id', __('游戏id'));
        $show->field('contact_details', __('联系方式'));
        $show->field('status', __('状态'));
        $show->field('remark', __('备注'));
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('更新时间'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $status = config('order.status'); //状态
        $form = new Form(new Order());
        $form->select('status', '状态')->options($status);
        $form->footer(function ($footer) {
            // 去掉`重置`按钮
            $footer->disableReset();
            // 去掉`查看`checkbox
            $footer->disableViewCheck();
            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();
            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();

        });
        return $form;
    }
}
